/**
 * 
 */
package com.h2.gwt.util;

import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.user.client.ui.Image;

/**
 *
 */
public final class ImageUtils {
   
   private ImageUtils() {
      //utility constructor
   }

   public static void preventDrag(Image image) {
      image.addMouseDownHandler(new MouseDownHandler() {
         public void onMouseDown(MouseDownEvent event) {
            event.preventDefault();
         }
      });
      preventDragIE(image.getElement());
   }
   
   private static native void preventDragIE(Element element) /*-{
      element.ondragstart = function() { return false; };
   }-*/;
   
   public static void preventSelection(Image image) {
      preventSelection(image.getElement());
   }
   
   public static native void preventSelection(Element element) /*-{
      element.style.MozUserSelect = 'none';
      element.unselectable = 'on';
      element.onselectstart = function() { return false; };
   }-*/;
   
}
